package com.ewanghuiju.app.ui.main.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.main.RedEnvelopesContract;
import com.ewanghuiju.app.model.bean.response.RedEnvelopesDetailsResponBean;
import com.ewanghuiju.app.presenter.main.RedEnvelopesPresenter;
import com.ewanghuiju.app.ui.main.adapter.RedEnvelopesAdapter;
import com.ewanghuiju.app.ui.my.activity.ShouyiCenterActivity;
import com.ewanghuiju.app.ui.my.activity.WalletCenterActivity;
import com.ewanghuiju.app.util.LoadingDialogUtils;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 红包列表页面
 * @time 2020/2/19
 */
public class RedEnvelopesActivity extends BaseActivity<RedEnvelopesPresenter> implements RedEnvelopesContract.View {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.tv_redbag_amount)
    TextView tvRedbagAmount;
    @BindView(R.id.tv_details_lab)
    TextView tvDetailsLab;

    private int currentPage = 1;

    private RedEnvelopesAdapter redEnvelopesAdapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_red_envelopes;
    }

    @Override
    protected void initEventAndData() {
        mToolbar.setBackground(null);
        mToolbar.setNavigationIcon(R.mipmap.icon_fan_white);
        intList();
        LoadingDialogUtils.show(mContext);
        mPresenter.getData(currentPage);
    }

    @OnClick({R.id.tv_wallet_balance})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_wallet_balance:
                new StartActivityUtil(mContext, WalletCenterActivity.class).startActivity(true);
                break;
            default:
                break;
        }
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(mToolbar, true)
                .statusBarDarkFont(true)
                .navigationBarDarkIcon(true)
                .init();
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    /**
     * 加载列表
     */
    private void intList() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
        linearLayoutManager.setSmoothScrollbarEnabled(true);
        recyclerView.setLayoutManager(linearLayoutManager);
        redEnvelopesAdapter = new RedEnvelopesAdapter(R.layout.item_red_envelopes);
        recyclerView.setAdapter(redEnvelopesAdapter);

    }

    @Override
    public void showContent(RedEnvelopesDetailsResponBean redEnvelopesDetailsResponBean) {
        LoadingDialogUtils.dismissDialog_ios();
        if (redEnvelopesDetailsResponBean != null && redEnvelopesDetailsResponBean.getList() != null && redEnvelopesDetailsResponBean.getList().size() > 0) {
            //有列表  更新
            tvRedbagAmount.setText(TextUtils.isEmpty(redEnvelopesDetailsResponBean.getUser_price()) ? "" : redEnvelopesDetailsResponBean.getUser_price());
            tvDetailsLab.setText("已领取" + redEnvelopesDetailsResponBean.getList().size() + "个");
            if (redEnvelopesAdapter != null) {
                redEnvelopesAdapter.setNewData(redEnvelopesDetailsResponBean.getList());
            }
        } else {
            //无数据

        }
    }

    @Override
    public void showMoreContent(String list) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
